const http = require('http')
const Koa = require('koa')
const favicon = require('koa-favicon');
const static = require('koa-static');
const session = require('koa-session-minimal')
const bodyParser = require('koa-bodyparser')

// const _DBMySQL = require('./dbs/db-mysql')
// const _mongoDB = require('./dbs/db-mongo')
// initDB()

//日志
const logMiddleWare = require('./logger');
const logger = require('./logger/logger');
const config = require('./config/sysConf.json')
const indexRouter = require('./routers')

const __root__ = process.cwd()
const logger = console
const app = new Koa()

app.use(favicon(`${__root__}/public/favicon.ico`));

// or use absolute paths
app.use(static(`${__root__}/public/`));

app.use(bodyParser())
app.use(session())
app.use(logMiddleWare())

app.use(indexRouter.routes())

app.use(indexRouter.allowedMethods())

module.exports = {
  app,
  logger,
  port: config.port,
}

// function initDB() {
//   global._UltDB = new _DBMySQL({
//     host: "10.254.218.134",
//     user: "yanjin",
//     port: 3306,
//     password: "Oke3.Dos9",
//     database: "masterdb",
//     charset: "utf8_general_ci"
//   })

//   global._WebDB = new _DBMySQL({
//     host: "localhost",
//     user: "root",
//     port: 3306,
//     password: "atmd@dd_2015",
//     database: "web_crawler",
//     charset: "utf8_general_ci"
//   })

//   global._webCrawlerMongo = new _mongoDB('mongodb://127.0.0.1:54188', 'web_crawler')

// }